package com.lxd.order.feign.clients;

import com.lxd.pojo.User;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.cloud.openfeign.FallbackFactory;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;

@FeignClient(value = "userservice",fallbackFactory = UserFallBackFactory.class)
public interface UserClient {
    @GetMapping("/user/{id}")
    User findById(@PathVariable("id") Long id);
}
@Component
class UserFallBackFactory implements FallbackFactory<UserClient> {
    private static final Logger LOGGER = LoggerFactory.getLogger(UserFallBackFactory.class);
    @Override
    public UserClient create(Throwable cause) {
        return new UserClient() {
            @Override
            public User findById(Long id) {
                LOGGER.error("调用异常:{}",cause);
                return null;
            }
        };
    }
}
